<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import LoginDialog from '@/components/LoginDialog.vue'
import { useUserMsgStore } from '@/stores/userMsg';
import { ArrowDown } from '@element-plus/icons-vue';
const userMsgStore = useUserMsgStore();
const router = useRouter();
let loginDialog = ref();

const handleCommand = (command: string | number | object) => {
    // console.log(command);
    if (command === 'logout') {
        userMsgStore.setUserInfo('', '');
        router.push('/');
    } else {
        router.push(command as string);
    }
}
</script>

<template>
    <div class="hospital-top">
        <div class="hospital-top-left" @click="router.push('/')">
            <img src="@/assets/images/logo.png" alt="商医通logo">
            尚医通 预约挂号统一平台
        </div>
        <div class="hospital-top-right">
            <i @click="router.push('/help')">帮助中心</i>
            <em v-if="userMsgStore.token" style="color: var(--gray-color2);">
                <el-dropdown @command="handleCommand">
                    <span class="el-dropdown-link">
                        {{ userMsgStore.name }}
                        <el-icon class="el-icon--right">
                            <arrow-down />
                        </el-icon>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item command="/user/certification">实名认证</el-dropdown-item>
                            <el-dropdown-item command="/user/order">挂号订单</el-dropdown-item>
                            <el-dropdown-item command="/user/patient">就诊人管理</el-dropdown-item>
                            <el-dropdown-item command="logout">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </em>
            <!-- <em v-if="userMsgStore.token" @click="userMsgStore.setUserInfo('', '')">退出登录</em> -->
            <em v-else @click="loginDialog.changeDialogVisible(true)">登录/注册</em>
        </div>
    </div>
    <teleport to='body'>
        <LoginDialog ref="loginDialog" />
    </teleport>
</template>

<style scoped lang="scss">
.hospital-top {
    height: 60px;
    background-color: #fff;
    // box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0px;
    z-index: 999;

    .hospital-top-left {
        display: flex;
        align-items: center;
        justify-content: start;
        font-size: 1.25rem;
        color: var(--theme-color);
        cursor: pointer;

        img {
            width: 50px;
            height: 50px;
            margin-right: 10px;
        }
    }

    .hospital-top-right {
        color: var(--gray-color1);

        i,
        em {
            cursor: pointer;
        }

        em {
            margin-left: 20px;
        }
    }
}

.example-showcase .el-dropdown-link {
    cursor: pointer;
    color: var(--el-color-primary);
    display: flex;
    align-items: center;
}
</style>